package com.system.healthproject.model.admin.controller;

import com.system.healthproject.bean.CardResultBean;
import com.system.healthproject.bean.PagesBean;
import com.system.healthproject.common.ApiResult;

import com.system.healthproject.model.admin.service.RechargeService;
import com.system.healthproject.pojo.Card;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @author Xuheng Zhou
 * @date 2020/6/9 11:06
 * @desc
 */
@Controller
@Api(value = "后台充值管理模块",tags = "后端-充值管理API")
@RequestMapping("/admin/Recharge")
public class RechargeController {

    @Autowired
    RechargeService rechargeService;

    /**
     * 多条件查询充值卡信息
     * @param cardType
     * @param createStartTime
     * @param createEndTime
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "多条件查询充值信息接口(接口已调用)",notes = "多条件查询充值信息",httpMethod = "post")
    @RequestMapping(value = "/selectRechargeWhere",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardType",value = "充值名称",dataType = "String"),
            @ApiImplicitParam(name = "createStartTime",value = "开始时间",dataType = "Date"),
            @ApiImplicitParam(name = "createEndTime",value = "结束时间",dataType = "Date"),
            @ApiImplicitParam(name = "page",value = "当前页数",dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "页数显示数据条数",dataType = "Integer")
    })
    public ApiResult<PagesBean<Card>> selectRechargeWhere(
            String cardType,
            String createStartTime,
            String createEndTime,
            Integer page,
            Integer size
    ){
        PagesBean<Card> cardPagesBean = rechargeService.selectList(page, size, cardType, createStartTime, createEndTime);
        return  ApiResult.successWithData("查询成功",cardPagesBean);
    }


    /**
     * 新增充值卡信息
     * @param card
     * @return
     */
    @ApiOperation(value = "充值信息新增接口(接口已调用)",notes = "新增充值卡信息",httpMethod = "post")
    @RequestMapping(value = "/insertRechargeCard",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public ApiResult insertRechargeCard(@RequestBody Card card) {
        boolean b = rechargeService.insertRechargeCard(card);
        return ApiResult.withBoolean(b,"新增充值卡成功","新增充值卡失败");
    }

    /**
     * 删除充值卡信息
     * @param cardId
     * @return
     */
    @ApiOperation(value = "充值信息删除接口(接口已调用)",notes = "删除充值卡信息",httpMethod = "post")
    @RequestMapping(value = "/deleteRechargeCard",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParam(name = "cardId",value = "充值卡id",dataType = "String",required = true)
    public ApiResult deleteRechargeCard(Integer cardId) {
        boolean b = rechargeService.deleteRechargeCard(cardId);
        return ApiResult.withBoolean(b,"删除充值卡成功","删除充值卡失败");
    }
}
